﻿using System;
using System.Data.OleDb;
using System.Windows.Forms;

namespace Texpro
{
    public partial class FMAD105 : Form
    {
        
        public FMAD105()
        {
            InitializeComponent();
        }

        private void FMAD105_Load(object sender, EventArgs e)
        {
            dtp_date.Value = PCPUB.m_tran_date;
        }

        private void but_ok_Click(object sender, EventArgs e)
        {
            DialogResult dr;
            if (validate_form())
            {
                dr = PCMSG.Show("Do you want to change date to " + dtp_date.Value.ToString("dd/MM/yyyy") + "?", "Change Date", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (dr == DialogResult.Yes)
                {
                    PCPUB.m_tran_date = dtp_date.Value;
                    this.Close();
                    PCMSG.Show("Date changed to " + PCPUB.m_tran_date.ToString("dd/MM/yyyy") + " successfully.", "Change Date");
                }
            }
        }

        private void but_cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void dtp_date_Validated(object sender, EventArgs e)
        {
            //if ( dtp_date.Value > PCPUB.m_tran_date)
            //{
            //    ep_form.SetError(dtp_date, "Change date should be future date.");
            //}
            //else if (dtp_date.Value.DayOfWeek.ToString() == "")
            //{
            //    ep_form.SetError(dtp_date, "Day of change date should be 'Sunday'.");
            //}
        }

        private bool validate_form()
        {
            //bool bln_error = false;
            String txt_error = String.Empty;
            ep_form.Clear();
            if (dtp_date.Value > PCPUB.m_get_date())
            {
                txt_error = "Changed date should not be future date.";
                ep_form.SetError(dtp_date, txt_error);
                PCMSG.ShowError(txt_error);
                dtp_date.Focus();
                return false;
            }
            else if (dtp_date.Value.DayOfWeek.ToString() == "Sunday")
            {
                txt_error = "Day of changed date should not be 'Sunday'.";
                ep_form.SetError(dtp_date, txt_error);
                PCMSG.ShowError(txt_error);
                dtp_date.Focus();
                return false;
            }
            return true;
        }

    }

}